/* Copyright - Apache License 2.0
 * 
 * The project "kyou" is
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *      http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.kyou.pack.segment.param;

import java.nio.charset.Charset;

import net.kyou.pack.PackContext;
import net.kyou.pack.segment.Segment;

/**
 * 求字符串的长度
 * 
 * @author NuclearG (<a href="mailto:nuclearg@163.com">nuclearg@163.com</a>)
 */
@ParamTag(name = "lens", postfix = ParamPostfix.Empty, type = ParamType.Int, require = ParamType.String)
class LenSParam extends BinaryParam {
    LenSParam(String expr, Segment segment, Param arg, Charset encoding) {
        super(expr, segment, arg, encoding);
    }

    @Override
    Object eval(Object result, PackContext context) {
        return ((String) result).length();
    }
}
